package com.xvyy.tingshu.album.api;

import com.xvyy.tingshu.album.service.BaseCategoryService;
import com.xvyy.tingshu.common.result.Result;
import com.xvyy.tingshu.model.album.BaseAttribute;
import com.xvyy.tingshu.model.album.BaseCategory3;
import com.xvyy.tingshu.vo.album.category.CategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.parsers.ReturnTypeParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value = "/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;
    @Qualifier("genericReturnTypeParser")
    @Autowired
    private ReturnTypeParser genericReturnTypeParser;

    //Request URL: http://192.168.217.1:8500/api/album/category/getBaseCategoryList
    @GetMapping("/getBaseCategoryList")
    @Operation(summary = "获取分类列表")
    public Result getBaseCategoryList() {

        List<CategoryVo> result = baseCategoryService.getBaseCategoryList();
        return Result.ok(result);
    }


    //Request URL: http://192.168.217.1:8500/api/album/category/findAttribute/2
    @GetMapping("/findAttribute/{category1Id}")
    @Operation(summary = "根据一级分类标签查询该分类标签信息")
    public Result findAttribute(@PathVariable("category1Id") Long category1Id) {

        List<BaseAttribute> result = baseCategoryService.findAttributeAndValue(category1Id);
        return Result.ok(result);
    }


    @GetMapping("/getC1Id7TopBaseCategory3List/{c1Id}")
    @Operation(summary = "根据一级分类c1Id获取7个置顶的三级分类对象")
    Result<List<BaseCategory3>> getC1Id7TopBaseCategory3List(@PathVariable(value = "c1Id") Long c1Id) {
        List<BaseCategory3> baseCategory3List = baseCategoryService.getC1Id7TopBaseCategory3List(c1Id);
        return Result.ok(baseCategory3List);
    }

    //http://192.168.217.1:8500/api/album/category/findTopBaseCategory3/1
    @GetMapping("/findTopBaseCategory3/{categoryId}")
    @Operation(summary = "根据一级分类id获取7个置顶的三级分类对象")
    public Result findTopBaseCategory3(@PathVariable("categoryId") Long categoryId) {

        List<BaseCategory3> c1Id7TopBaseCategory3List = baseCategoryService.getC1Id7TopBaseCategory3List(categoryId);
        return Result.ok(c1Id7TopBaseCategory3List);
    }


    //http://192.168.217.1:8500/api/album/category/getBaseCategoryList/1
    @GetMapping("/getBaseCategoryList/{c1Id}")
    @Operation(summary = "根据一级分类id获取二级和三级分类对象")
    public Result getBaseCategoryList(@PathVariable("c1Id") Long c1Id) {
        CategoryVo categoryVo = baseCategoryService.getBaseCategoryList(c1Id);
        return Result.ok(categoryVo);
    }
}

